//
//  GameTalbeViewCell.m
//  NBAPro
//
//  Created by 李广松 on 16/7/12.
//  Copyright © 2016年 WYH. All rights reserved.
//

#import "GameTalbeViewCell.h"

@implementation GameTalbeViewCell

@synthesize groundView, leftTeamIconImgView, rightTeamIconImgView, leftCityLab, rightCityLab, leftNameLab, rightNameLab, leftScoreLab, rightScoreLab, qrtLabel;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        groundView = [self createBackgroundViewWithFrame:CGRectMake(16, 8, 414 - 32, 130 - 16)];
        [self addSubview:groundView];
        
        UILabel *centerLineLab = [CreateControl createLabelWithFrame:CGRectMake(groundView.frame.size.width / 2 - 0.5, groundView.frame.size.height / 2 - 40 / 2 + 7, 1, 40) AndText:nil AndTextColor:nil AndBackgroundColor:[UIColor whiteColor] AndTextFont:0];
        [groundView addSubview:centerLineLab];
        
        qrtLabel = [CreateControl createLabelWithFrame:CGRectMake(centerLineLab.frame.origin.x - 70, centerLineLab.frame.origin.y - 22, 141, 12) AndText:@"Q4 0:00" AndTextColor:[UIColor whiteColor] AndBackgroundColor:[UIColor clearColor] AndTextFont:10];
        [groundView addSubview:qrtLabel];
        
        leftTeamIconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(54, 25, 60, 60)];
        rightTeamIconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(groundView.frame.size.width - 22 - 60, leftTeamIconImgView.frame.origin.y, 60, 60)];
        [self addSubview:leftTeamIconImgView];
        [self addSubview:rightTeamIconImgView];
        
        leftCityLab = [self createCityLabelWithFrame:CGRectMake(leftTeamIconImgView.frame.origin.x + leftTeamIconImgView.frame.size.width / 2 - 80, leftTeamIconImgView.frame.origin.y + leftTeamIconImgView.frame.size.height, 160, 11)];
        leftNameLab = [self createNameLabelWithFrame:CGRectMake(leftTeamIconImgView.frame.origin.x + leftTeamIconImgView.frame.size.width / 2 - 80, leftCityLab.frame.origin.y + leftCityLab.frame.size.height, 160, 12)];
        [self addSubview:leftCityLab];
        [self addSubview:leftNameLab];

        rightCityLab = [self createCityLabelWithFrame:CGRectMake(rightTeamIconImgView.frame.origin.x + rightTeamIconImgView.frame.size.width / 2 - 80, leftCityLab.frame.origin.y, 160, 11)];
        rightNameLab = [self createNameLabelWithFrame:CGRectMake(rightCityLab.frame.origin.x, rightCityLab.frame.origin.y + rightCityLab.frame.size.height, 160, 12)];
        [self addSubview:rightCityLab];
        [self addSubview:rightNameLab];
        
        leftScoreLab = [self createTeamScoreLabWithFrame:CGRectMake(groundView.frame.size.width / 2 - 101 - 8, centerLineLab.frame.origin.y + centerLineLab.frame.size.height / 2 - 7, 100, 30)];
        rightScoreLab = [self createTeamScoreLabWithFrame:CGRectMake(groundView.frame.size.width / 2 + 33 + 8, leftScoreLab.frame.origin.y, 100, 30)];
        [self addSubview:leftScoreLab];
        [self addSubview:rightScoreLab];
        
        
        
    }
    
    return self;
}

- (UILabel *)createTeamScoreLabWithFrame:(CGRect)frame {
    UILabel *label = [self createLabelWithFrame:frame];
    label.font = [UIFont systemFontOfSize:30];
    if (label.frame.origin.x > self.frame.size.width / 2) {
        label.textAlignment = NSTextAlignmentLeft;
    }
    else {
        label.textAlignment = NSTextAlignmentRight;
    }
    
    
    return label;
}

- (UILabel *)createCityLabelWithFrame:(CGRect)frame {
    UILabel *label = [self createLabelWithFrame:frame];
    label.font = [UIFont systemFontOfSize:11];
    label.textAlignment = NSTextAlignmentCenter;
    
    return label;
}

- (UILabel *)createNameLabelWithFrame:(CGRect)frame {
    UILabel *label = [self createLabelWithFrame:frame];
    label.font = [UIFont fontWithName:FONT_Hel  size:12];
    label.textAlignment = NSTextAlignmentCenter;
    
    return label;
    
}


- (UIView *)createBackgroundViewWithFrame:(CGRect)frame {
    UIView *view = [[UIView alloc] initWithFrame:frame];
    view.layer.cornerRadius = 7;
    return view;
}

- (UILabel *)createLabelWithFrame:(CGRect)frame {
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.textColor = [UIColor whiteColor];
    
    return label;
}


@end
